/**
 * Author:yuiop
 * Date:2022/8/2 11:14
 */
package com.devops.graphql.handler;

import com.netflix.graphql.types.errors.ErrorType;
import graphql.ErrorClassification;
import graphql.GraphQLError;
import graphql.language.SourceLocation;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class CustomGraphQLError implements GraphQLError {
    private final String message;
    private final String code;


    public CustomGraphQLError(String message, String code) {
        this.message = message;
        this.code = code;
    }

    @Override
    public String getMessage() {
        return message;
    }


    @Override
    public List<SourceLocation> getLocations() {
        return null;

    }

    @Override
    public ErrorClassification getErrorType() {
        return ErrorType.INTERNAL;
    }

    @Override
    public Map<String, Object> getExtensions() {
        Map<String, Object> customAttributes = new LinkedHashMap<>();
        customAttributes.put("message", message);
        customAttributes.put("code", code);
        return customAttributes;
    }
}
